home *** CD-ROM | disk | FTP | other *** search
- Path: news.campus.mci.net!usenet
- From: Kevin Wilson <kevinw@telis.org>
- Newsgroups: comp.lang.c++
- Subject: revised derived class question
- Date: Sun, 17 Mar 1996 10:17:43 -0800
- Organization: MCI State Government and University Systems
- Message-ID: <314C5747.19D9@telis.org>
- NNTP-Posting-Host: s25-pm02.mtsac.campus.mci.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Thanks much for the quick reply everybody...
-
- Unfortunately I included screwed up listings in my news post... I was too busy trying every
- possible fix I could think of so you got a mish-mash of crap. Below are correct listings of
- what I was trying to do.
-
- The Llist::Retreive function returns a pointer to Llist object, a single entry in the list.
-
- Stack::Pop uses Retreive to grab the first object in the list.
-
- My compiler gives the following error:
- c:\src\cpsc352\hw2\stacklib.cpp(13) : error C2446: '=' : no conversion from 'class ::Llist
- __far *' to 'class ::Stack __far *'
-
- It wants a type conversion from Llist to Stack... Not sure how to do that and I didnt think I
- had to for a derived class.
- ---------------------------------llist.h-----------------------------------------------
- #define NULL 0
-
- class Llist{
- private:
- char *str; //points to list element
- Llist *nxt; //points to next element in list
- static Llist head; //list head
- static int nvals; //holds number of elements in list
- public:
- Llist();
- Llist(char *x, Llist *ptr);
- ~Llist();
- int Insert(char *x, int p);
- int Locate(char *x);
- Llist *Retreive(int p);
- int Delete(int p);
- int First();
- int Next(int p);
- int Previous(int p);
- int Last();
- int End();
- int MakeNull();
- void PrintList();
- friend ostream& operator<<(ostream& os, Llist& L);
- };
-
- ---------------------------------stack.h----------------------------------------------
- //
- // Stack lib using link list class as base
- //
-
- #include "llist.h"
-
- class Stack:public Llist {
- public:
- Stack(void);
- ~Stack();
- Stack *Pop(void);
- int Push(char *);
- };
-
-
- ---------------------------------stacklib.h-------------------------------------------
- #include <iostream.h>
- #include "stack.h"
-
- Stack::Stack():Llist()
- {}
- Stack::~Stack(){}
-
- Stack *Stack::Pop()
- {
- Stack *ptr;
-
- ptr = Retreive(1);
- if(ptr != NULL)
- Llist::Delete(1);
- return ptr;
- }
-
- int Stack::Push(char *x)
- {
- return Llist::Insert(x, 1);
- }
-